package com.qf;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;

@Configuration
public class BeanConfig {
    @Bean
    public RedisTemplate redisTemplate(RedisTemplate redisTemplate) {
        //实现了key value自定义序列化方式
        redisTemplate.setKeySerializer(RedisSerializer.string());//字符串
        redisTemplate.setValueSerializer(new Jackson2JsonRedisSerializer<Object>(Object.class));//利用Jackson序列化为json
        redisTemplate.setHashKeySerializer(RedisSerializer.string());
        redisTemplate.setHashKeySerializer(new Jackson2JsonRedisSerializer<Object>(Object.class));
        return redisTemplate;
    }
}
